home *** CD-ROM | disk | FTP | other *** search
/ Sony Community Place / BROWSER / APP / CHAT / CHATROOM.EXE / program files / Sony / Community Place Browser / world / chatroom / scripts / guess.java < prev    next >
Encoding:
Java Source  |  1996-12-12  |  3.0 KB  |  108 lines

  1. /*
  2.  * Copyright(C) 1996 Sony Corporation. All rights reserved.
  3.  */
  4.  
  5. import vrml.*;
  6. import vrml.field.*;
  7. import vrml.node.*;
  8. import java.util.*;
  9. import vs.*;
  10.  
  11. public class guess extends Script{
  12.     /* Node */
  13.     SFNode        GuessNode;
  14.  
  15.     /* EventOut */
  16.     SFString        GuessAppearanceDescription;
  17.     SFBool            GuessTimeSensorEnabled;
  18.     public void initialize() {
  19.         /* Node */
  20.         GuessNode                = (SFNode) getField( "GuessNode" );
  21.  
  22.         /* EventOut */
  23.         GuessAppearanceDescription        = (SFString) getEventOut( "GuessAppearanceDescription" );
  24.         GuessTimeSensorEnabled        = (SFBool) getEventOut( "GuessTimeSensorEnabled" );
  25.     }
  26.  
  27.     public void processEvent(Event e) {
  28.         String name = e.getName () ;
  29.  
  30.         if(name.equals("GuessTouchSensorIsActive")) {    GuessTouchSensorIsActive(e);    }
  31.         if(name.equals("GuessPlaneSensorIsActive")) {    GuessPlaneSensorIsActive(e);    }
  32.         if(name.equals("GuessShareTouched")){            GuessShareTouched(e);        }
  33.     }
  34.  
  35.     public void GuessTouchSensorIsActive(Event e) {
  36.         double time = e.getTimeStamp();
  37.         ConstSFBool mouse_down = (ConstSFBool)e.getValue();
  38.     
  39.         if (mouse_down.getValue()) {    /* mouseDown */
  40.             GuessTimeSensorEnabled.setValue(true);
  41.         } else {
  42.             GuessTimeSensorEnabled.setValue(false);
  43.             GuessCommentDisplay();
  44.             Vscp.sendApplSpecificMsgWithDist( GuessNode, "GuessShareTouched", "void", Vscp.allClientsExceptMe );
  45.         }
  46.     }
  47.  
  48.     public void GuessPlaneSensorIsActive(Event e) {
  49.         double time = e.getTimeStamp();
  50.         ConstSFBool mouse_down = (ConstSFBool)e.getValue();
  51.     
  52.         if (mouse_down.getValue()) return;    /* mouseDown */
  53.         
  54.         GuessCommentDisplay();
  55.         Vscp.sendApplSpecificMsgWithDist( GuessNode, "GuessShareTouched", "void", Vscp.allClientsExceptMe );
  56.     }
  57.  
  58.  
  59.     public void GuessShareTouched(Event e) {
  60.         //double time = e.getTimeStamp();
  61.  
  62.         GuessCommentDisplay();
  63.  
  64.     }
  65.  
  66.     public void GuessCommentDisplay () {
  67.         String txt = "";
  68.         int num;
  69.     
  70.     num = randMinMax(0, 8);
  71.     switch (num) {
  72.         case 0: txt = "Welcome!!\nYour name is ";    break;
  73.         case 1: txt = "There is a light switch in this room. \nLet's turn off the light.\n";    break;
  74.         case 2: txt = "Looking good!\n";    break;
  75.         case 3: txt = "Hi!\nGo to the second floor! \nYou can climb the stairs.\n";    break;
  76.         case 4: txt = "You can fly.\nCtrl+Click on the roof!\n";    break;
  77.         case 5: txt = "To play a game,\nGo to the Bouncing Room!\n";    break;
  78.         case 6: txt = "To leave your own message,\nGo to the White Board Room.\n";    break;
  79.         case 7: txt = "There is an object which tells you your lucky color\nin this room!\n";    break;
  80.         case 8: txt = "In this room, \nAn elevator object is available.\n";    break;
  81.     }
  82.     /*
  83.     switch $mode {
  84.         0 { set t "I Guess your name .." }
  85.         1 { set t "$s$name" }
  86.     }
  87.     */
  88.     //GuessTimeSensorEnabled.setValue(true);
  89.     GuessAppearanceDescription.setValue(txt);
  90.  
  91.     }
  92.  
  93.     int randMinMax(int min,int max){
  94.         int value;
  95.         int range;
  96.         double rnd;
  97.  
  98.         range = max - min;
  99.         rnd = Math.random();
  100.         value = (int)(rnd * (double)range) + min;
  101.  
  102.         return value;
  103.     }
  104. }
  105.  
  106.  
  107.  
  108.